import path from 'path';
import { MessageContext, VK } from 'vk-io';
import { VKOptions } from 'vk-io/lib/types';
import { Commander } from './core/commander';
import * as commands from './commands';
import dotenv from 'dotenv';

dotenv.config({
  path: path.join(__dirname, '../.env')
})

const defaultVkOPtions: Partial<VKOptions> = {
  apiMode: 'parallel',
  apiRequestMode: 'burst',
}

export const groupVk = new VK({
  token: process.env.GROUP_TOKEN!,
  ...defaultVkOPtions,
});

export const userVk = new VK({
  token: process.env.USER_TOKEN!,
  ...defaultVkOPtions,
});

const commander = new Commander<MessageContext>();

Object.values(commands).forEach(commander.addCommand)

groupVk.updates.on('message', commander.middleware)

groupVk.updates.start()
  .then(() => console.info('VK: group updates started'));
